﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC_Uthorization.Read.API.Application.Command.RoleMenuCommand;
using RBAC_Uthorization.Read.API.Application.Command.RoleMenuFunCommand;
using RBAC_Uthorization.Read.API.Application.CommandHandlers.RoleMenuHandler;
using RBAC_Uthorization.Read.API.DTO;
using System.Security.Claims;

namespace RBAC_Uthorization.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class RoleMenuFunController : ControllerBase
    {
        private readonly IMediator _mediator;

        public RoleMenuFunController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 根据菜单id查询功能权限
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<string[]>> RoleMenuFunId(int menuId)
        {
            return await _mediator.Send(new RoleMenuFunIdCommand() {
                MenuId = menuId,
                RoleId = HttpContext.User.FindFirst(ClaimTypes.GroupSid)?.Value 
            });
        }
        /// <summary>
        /// 根据角色id查看菜单详情
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<string>>> RoleMenuFunByRoleId(int roleId)
        {
            return await _mediator.Send(new RoleMenuFIndIdCommand()
            {
                RoleId = roleId

            });
        }

    }
}
